﻿<UserControl x:Class="EasyToolkit.UI.MetroFormWpfContainer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:ControlsMetro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             mc:Ignorable="d"
             xmlns:local="clr-namespace:EasyToolkit.UI"
             d:DesignHeight="300" d:DesignWidth="300"  Background="Transparent"
             FontFamily="Segoe UI Symbol"
>
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static local:MetroFormWpfContainer.CloseWindowCommandRouted}" Executed="OnCloseWindow"/>
    </UserControl.CommandBindings>
    
    <UserControl.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BoolToVis" />
            <sys:Double x:Key="TitleBarHeight">30</sys:Double>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\Icons.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" x:Name="TitleBar" HorizontalAlignment="Stretch" Background="{DynamicResource WindowTitleColorBrush}" Margin="0">
            <Grid Margin="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>

                <Grid Grid.Column="0" Background="{DynamicResource HighlightBrush}" Width="{StaticResource TitleBarHeight}" Height="{StaticResource TitleBarHeight}" Visibility="{Binding Path=HasIcon, Converter={StaticResource BoolToVis}}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0">
                    <Path Stretch="Fill" DataContext="{DynamicResource MainIcon}" Data="{Binding Path=Data}" Fill="White"/>
                </Grid>
                <ContentControl Grid.Column="1" MouseMove="OnMouseMove" VerticalContentAlignment="Center" Margin="5,0,0,0">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDoubleClick" >
                            <i:InvokeCommandAction Command="{Binding MaxRestoreCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <Label  HorizontalAlignment="Stretch" Content="{Binding Title}" FontSize="18" Foreground="White"/>
                </ContentControl>
            </Grid>

            <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0">
                <Button Command="{Binding MaxRestoreCommand}"
                        FocusVisualStyle="{x:Null}"
                        IsTabStop="False"
                        Width="{StaticResource TitleBarHeight}"
                        Height="{StaticResource TitleBarHeight}"
                        Style="{DynamicResource IronicallyNamedChromelessButtonStyle}"
                        Padding="0"
                        Foreground="White"
                        ToolTip="{Binding Maximize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ControlsMetro:WindowButtonCommands}}}">
                    <Grid>
                        <Grid Visibility="{Binding Path=IsWindowStatusMax, Converter={StaticResource BoolToVis}}">
                            <Path DataContext="{StaticResource icon_WindowStatusNormal}" Data="{Binding Path=Data}" Fill="White" />
                        </Grid>
                        <Grid Visibility="{Binding Path=IsWindowStatusNormal, Converter={StaticResource BoolToVis}}">
                            <Path DataContext="{StaticResource icon_WindowStatusRestore}" Data="{Binding Path=Data}" Fill="White" />
                        </Grid>
                    </Grid>
                </Button>
                <Button Command="{x:Static local:MetroFormWpfContainer.CloseWindowCommandRouted}" 
                        Foreground="White"
                        FocusVisualStyle="{x:Null}"
                        IsTabStop="False"
                        Width="{StaticResource TitleBarHeight}"
                        Height="{StaticResource TitleBarHeight}"
                        Style="{DynamicResource IronicallyNamedChromelessButtonStyle}"
                        ToolTip="{Binding Close, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ControlsMetro:WindowButtonCommands}}}">
                    <Path DataContext="{StaticResource icon_WindowClose}" Data="{Binding Path=Data}" Fill="White" />
                </Button>
            </StackPanel>
        </Grid>
        <Grid x:Name="ControlContainer" Grid.Row="1" DataContext="{Binding ControlContainerViewModel}"/>
    </Grid>
</UserControl>
